#include <iostream>
#include <algorithm>
using namespace std;

const int N = 1e5 + 4;
int a[N], dp[N];

int main()
{
    int n;
    cin >> n;
    int x = 0;
    for (int i = 1; i <= n; i++)
    {
        int k;
        cin >> k;
        a[k]++;
        x = max(x, k);
    }
    dp[1] = a[1];
    int ans = 0;
    for (int i = 2; i <= x; i++)
    {
        dp[i] = max(dp[i - 1], dp[i - 2] + a[i] * i);
        ans = max(ans, dp[i]);
    }
    cout << ans;
    return 0;
}